package com.easy.controller;

import java.util.List;

import com.easy.entity.query.DeptQuery;
import com.easy.entity.po.Dept;
import com.easy.entity.vo.ResponseVO;
import com.easy.service.DeptService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 部门表 Controller
 */
@RestController("deptController")
@RequestMapping("/dept")
public class DeptController extends ABaseController{

	@Resource
	private DeptService deptService;
	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("/loadDataList")
	public ResponseVO loadDataList(DeptQuery query){
		return getSuccessResponseVO(deptService.findListByPage(query));
	}

	/**
	 * 新增
	 */
	@RequestMapping("/add")
	public ResponseVO add(Dept bean) {
		deptService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("/addBatch")
	public ResponseVO addBatch(@RequestBody List<Dept> listBean) {
		deptService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增/修改
	 */
	@RequestMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Dept> listBean) {
		deptService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@RequestMapping("/getDeptById")
	public ResponseVO getDeptById(Integer id) {
		return getSuccessResponseVO(deptService.getDeptById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@RequestMapping("/updateDeptById")
	public ResponseVO updateDeptById(Dept bean,Integer id) {
		deptService.updateDeptById(bean,id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("/deleteDeptById")
	public ResponseVO deleteDeptById(Integer id) {
		deptService.deleteDeptById(id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Name查询对象
	 */
	@RequestMapping("/getDeptByName")
	public ResponseVO getDeptByName(String name) {
		return getSuccessResponseVO(deptService.getDeptByName(name));
	}

	/**
	 * 根据Name修改对象
	 */
	@RequestMapping("/updateDeptByName")
	public ResponseVO updateDeptByName(Dept bean,String name) {
		deptService.updateDeptByName(bean,name);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Name删除
	 */
	@RequestMapping("/deleteDeptByName")
	public ResponseVO deleteDeptByName(String name) {
		deptService.deleteDeptByName(name);
		return getSuccessResponseVO(null);
	}
}